//
//  GSLocalAuthUserInfoView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/25.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "GSLocalAuthUserInfoView.h"

@interface GSLocalAuthUserInfoView ()

//@property (nonatomic, strong) QMUIButton *button;

@property (nonatomic, strong) UIImageView *headIV;

/**
 *nameLabel
 */
@property (nonatomic, strong) QMUILabel *nameLabel;

@end

@implementation GSLocalAuthUserInfoView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    CGFloat headIVWidth = 68.0;
    self.headIV = [UIImageView new];
    self.headIV.contentMode = UIViewContentModeScaleAspectFill;
    self.headIV.layer.masksToBounds = true;
    [self addSubview:self.headIV];
    [self.headIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.mas_centerY);
        make.centerX.mas_equalTo(self);
        make.width.height.mas_equalTo(headIVWidth);
    }];
    self.headIV.layer.cornerRadius = headIVWidth/2;
    //
    self.nameLabel = [QMUILabel new];
    self.nameLabel.textColor = GSLOGINRGBRGBHEX(0x000000);
    self.nameLabel.font = [UIFont systemFontOfSize:25 weight:UIFontWeightMedium];
    self.nameLabel.adjustsFontSizeToFitWidth = true;
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_centerY);
        make.centerX.mas_equalTo(self);
        make.width.mas_equalTo(self);
    }];
}

- (void)setUserInfo:(UserInfoModel *)userInfo {
    _userInfo = userInfo;
    //
    [self.headIV sd_setImageWithURL:[NSURL URLWithString:userInfo.head_img] placeholderImage:LOAD_IMAGE(@"default_head")];
    //
    NSString *account = userInfo.nickname;
    if (!account.length) {
        account = userInfo.phone;
    }
    if (!account.length) {
        account = userInfo.email;
    }
    self.nameLabel.text = [NSString stringWithFormat:@"Hi, %@",account];
}

@end
